<?php
declare (strict_types = 1);

namespace app\api\controller\v1;


use think\facade\Request;
use app\api\service\StatusCode;
use app\api\service\UserToken;
use app\api\model\TodoList as ModelTodoList;
use app\api\validate\TodoList as ValidateTodoList;
use app\api\validate\ParamMustBePostiveInt;

/**
 * 教师端事项管理
 */
class TodoList extends Api
{
    /**
     * 
     * 获取所有事项
     */
    public function index()
    {
        $uid =  UserToken::getCurrentUid();
        $job = 0;
        $data = ModelTodoList::getTodoList($uid,$job);
        exit(json_encode($data));
    }
    /**
     * 
     * 删除单个代办事项
     */
    public function delete()
    {
        $id = (new ParamMustBePostiveInt())->paramCheck();
        $success = ModelTodoList::delTodoList($id);
        $this->return_msg(StatusCode::SUCCESS,'删除成功',$success);
    }
    /**
     * 
     * 新增事项
     */
    public function create()
    {
        $data = Request::post();
        validate(ValidateTodoList::class)->scene('createTodoList')->check($data);
        $data["user_id"] = UserToken::getCurrentUid();
        $data['job'] = 0;
        $success = ModelTodoList::addTodoList($data);
        $this->return_msg(StatusCode::SUCCESS,'新增成功', $success);
    }
    /**
     * 
     * 修改状态
     */
    public function edit()
    {
        $id = (new ParamMustBePostiveInt())->paramCheck();
        $data = Request::get();
        validate(ValidateTodoList::class)->scene('editTodoList')->check($data);
        $success = ModelTodoList::editTodoList($id,$data['status']);
        $this->return_msg(StatusCode::SUCCESS,'修改成功', $success);
    }

}